package com.ebt.m.wiki.view;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.utils.UIHelper;

/**
 * 产品选项 抽象类
 *
 * @author Michael.li
 */
public class ProdcutOptionView extends TextView {
    /**
     * 默认状态
     **/
    public static final int STATE_DEFAULT = 0;
    /**
     * 选中状态
     **/
    public static final int STATE_SELECTED = 1;
    /**
     * 不可用状态
     **/
    public static final int STATE_DISABLED = 2;

    private int mState = STATE_DEFAULT;
    private int mValue;

    public ProdcutOptionView(Context context) {
        super(context, null);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 0, UIHelper.dip2px(context, 10), 0);
        setLayoutParams(params);
        setTextSize(14);
        setGravity(Gravity.CENTER);
        setState(STATE_DEFAULT);
        // 添加间隔
        int left = UIHelper.dip2px(context, 3);
        setPadding(left, left, left, left);
    }

    /**
     * 设置值
     *
     * @param value
     */
    public void setValue(int value) {
        mValue = value;
//		setText(getText(value));
    }

    /**
     * 设置状态
     *
     * @param state
     */
    public void setState(int state) {
        mState = state;
        setTextColor(getColor(state));
        setBackgroundResource(getBackground(state));
        if (state == STATE_DISABLED) {
            // 移除点击事件
            setOnClickListener(null);
        }
    }

    /**
     * 获得状态
     *
     * @return
     */
    public int getState() {
        return mState;
    }

    /**
     * 获取值
     *
     * @return
     */
//	public int getValue()
//	{
//		return mValue;
//	}
    private int getColor(int state) {
        switch (state) {
            case STATE_DEFAULT:
//			return Color.BLACK;
                return Color.parseColor("#ffbbbbbb");
            case STATE_SELECTED:
                return getResources().getColor(R.color.common_bg_bar);
            default:
                return Color.parseColor("#ffbbbbbb");
        }
    }

    protected int getBackground(int state) {
        switch (state) {
            case STATE_DEFAULT:
//			return R.drawable.wiki_option_default;
                return R.drawable.cacurlator_item_unselected;
            case STATE_SELECTED:
//			return R.drawable.wiki_option_selected;
                return R.drawable.cacurlator_item_selected;
            default:
                return R.drawable.cacurlator_item_unable;
        }
    }

//	protected String getText(int value)
//	{
//		if (value == 0) {
//			return "趸交";
//		} else if (value > 0) {
//			return value + "年";
//		} else {
//			return "至" + Math.abs(value) + "岁";
//		}
//	}
}
